<html>
<head>
<title>Eggs</title>
</head>

<body>

<center>
<h1>POI VII Stage 3 Problem 2</h1>
<h1>Eggs</h1>
</center>

<p>
    It is known, that if an egg is dropped from a sufficient height it breaks ugly.
    Formerly (the height of) the first floor was enough, but genetically muted hens
    lay eggs which don't break even after falling down from the height
    of the 100000000-th floor.

    Researches on toughness of eggs are proceeded in skyscrapers. A special
    scale of toughness of eggs has been developed: an egg has toughness of
    <i>k</i> floors if it doesn't break after falling down from the 
    <i>k</i>-th
    floor but it breaks after falling down from the <i>k+1</i>-st 
one. If our skyscraper
    has <i>n</i> floors, we assume that every egg breaks after falling
    down from the <i>n+1</i>-st floor.
    We also assume that every egg dropped from the 0-th floor doesn't break.
</p>

<p>
    The manager of the laboratory resolved to cut down expences on research.
    He limited the number of eggs, which can be broken during a single experiment purposed
    to determine the toughness of eggs of a given kind.
    Moreover the number of egg drops has to be minimized. It means that given
    a fixed number of eggs of a given kind and a skyscraper one has to determine, in the minimum number
    of drops, what is the toughnes of eggs of this kind.
</p>

<h2>Task</h2>
<p>
    Your task is to write a module containing three procedures
      (functions in case of C/C++ language):
</p>

<ul>
        <li><tt>nowy_eksperyment</tt> - this procedure will be called at the 
	        beginning of a new experiment (there can be more than one);
        <li><tt>daj_pytanie</tt> - this procedure is used for asking a question: Does
 		 an egg break, if it is dropped from a given floor?;
	        to ask the question one has to put the number of the floor (from which 
		she/he is going to drop an egg) into a global variable <tt>pietro</tt> 
                described below;
        <li><tt>analizuj_odpowiedz</tt> - this procedure should read the value 
	          of the global variable <tt>odpowiedz</tt>, which contains the
                answer to the recent question (description of this variable is 
                given below), and analyse the answer. If as a result of this analysis the 
   		    toughness of a given kind of eggs is found, the procedure should indicate 
                this fact by placing proper values into global variables <tt>x</tt> and 
                <tt>wiem</tt> (details are given below).
</ul>

<p>
      At the beginning of every experiment the program inspecting the run of the experiment 
      will call the procedure <tt>nowy_eksperyment</tt> written by you and then it will
      repeat the following actions:
</p>

 <ul>
        <li>calling procedure <tt>daj_pytanie</tt>,
        <li>answering a question,
        <li>calling procedure <tt>analizuj_odpowiedz</tt>,
 </ul>

<p>
      till the moment when your program has confirmed that it knows the toughness
      of eggs 
      examined in the experiment (i.e. the procedure <tt>analizuj_odpowiedz</tt> 
      puts the proper value into the global variable <tt>wiem</tt>).
</p>

<p>
      <b>Note:</b> Don't assume that a program  inspecting the run of experiments actually
      fixes the toughness of eggs before starting the experiment. It can adjust it during
      the experiment, so that it suits to all previously given answers and makes
      your program ask maximum number of questions.
      Thus, you should try to minimize the number of questions, which your program
      would have to
      ask in the worst case.
</p>

<h2>Communication</h2>
<p>
      The communication between your module and the program inspecting the run
      of experiments is done through global variables.

      The number of floors of the skyscraper will be written in the global variable
      <tt>wysokosc</tt> of type <tt>Longint</tt> (in case of C/C++ language the 
      type is  <tt>long int</tt>).
      It will be a positive integer not greater than 100000000.

      The maximal number of eggs that can be broken during the experiment
      will be written in the global variable <tt>jajka</tt> of type <tt>Integer</tt> 
      (in case of C/C++ language the type is  <tt>int</tt>).
      It will be a positive integer not greater than 1000.

      Asking a question if an egg "survives" a fall from the <i>k</i>-th floor,
      is done in the procedure <tt>daj_pytanie</tt> by putting the number
      <i>k</i> into the 
      global variable <tt>pietro</tt> of type <tt>Longint</tt> 
      (in case of C/C++ language the type is  <tt>long int</tt>).

      The answer to the question is put into the global variable <tt>odpowiedz</tt> 
      of type <tt>Boolean</tt> (in case of C/C++ language the type is <tt>int</tt>).
      The confirmation  to the question (i.e. the egg "survives") corresponds
      to the value <tt>TAK</tt>, and a negative answer (i.e. the egg breaks) corresponds to the value
      <tt>NIE</tt>, where <tt>TAK</tt> and <tt>NIE</tt> are constants valued respectively 
      to <tt>true</tt> and <tt>false</tt> (in case of C/C++ language these are macros valued
      respectively to <tt>1</tt> and <tt>0</tt>).

      When your program determines the toughness of the egg it should write in the procedure
      <tt>analizuj_odpowiedz</tt> a value <tt>TAK</tt> into the global variable <tt>wiem</tt> of type 
      <tt>Boolean</tt> (in case of C/C++ language the type is <tt>int</tt>) 
       and the toughness of  the egg found by your program should be written into the global 
      variable <tt>x</tt> of
       type <tt>Longint</tt> (in case of C/C++ language<html>
<head>
<title>Eggs</title>
</head>

<body>

<center>
<h1>POI VII Stage 3 Problem 2</h1>
<h1>Eggs</h1>
</center>

<p>
    It is known, that if an egg is dropped from a sufficient height it breaks ugly.
    Formerly (the height of) the first floor was enough, but genetically muted hens
    lay eggs which don't break even after falling down from the height
    of the 100000000-th floor.

    Researches on toughness of eggs are proceeded in skyscrapers. A special
    scale of toughness of eggs has been developed: an egg has toughness of
    <i>k</i> floors if it doesn't break after falling down from the 
    <i>k</i>-th
    floor but it breaks after falling down from the <i>k+1</i>-st 
one. If our skyscraper
    has <i>n</i> floors, we assume that every egg breaks after falling
    down from the <i>n+1</i>-st floor.
    We also assume that every egg dropped from the 0-th floor doesn't break.
</p>

<p>
    The manager of the laboratory resolved to cut down expences on research.
    He limited the number of eggs, which can be broken during a single experiment purposed
    to determine the toughness of eggs of a given kind.
    Moreover the number of egg drops has to be minimized. It means that given
    a fixed number of eggs of a given kind and a skyscraper one has to determine, in the minimum number
    of drops, what is the toughnes of eggs of this kind.
</p>

<h2>Task</h2>
<p>
    Your task is to write a module containing three procedures
      (functions in case of C/C++ language):
</p>

<ul>
        <li><tt>nowy_eksperyment</tt> - this procedure will be called at the 
	        beginning of a new experiment (there can be more than one);
        <li><tt>daj_pytanie</tt> - this procedure is used for asking a question: Does
 		 an egg break, if it is dropped from a given floor?;
	        to ask the question one has to put the number of the floor (from which 
		she/he is going to drop an egg) into a global variable <tt>pietro</tt> 
                described below;
        <li><tt>analizuj_odpowiedz</tt> - this procedure should read the value 
	          of the global variable <tt>odpowiedz</tt>, which contains the
                answer to the recent question (description of this variable is 
                given below), and analyse the answer. If as a result of this analysis the 
   		    toughness of a given kind of eggs is found, the procedure should indicate 
                this fact by placing proper values into global variables <tt>x</tt> and 
                <tt>wiem</tt> (details are given below).
</ul>

<p>
      At the beginning of every experiment the program inspecting the run of the experiment 
      will call the procedure <tt>nowy_eksperyment</tt> written by you and then it will
      repeat the following actions:
</p>

 <ul>
        <li>calling procedure <tt>daj_pytanie</tt>,
        <li>answering a question,
        <li>calling procedure <tt>analizuj_odpowiedz</tt>,
 </ul>

<p>
      till the moment when your program has confirmed that it knows the toughness
      of eggs 
      examined in the experiment (i.e. the procedure <tt>analizuj_odpowiedz</tt> 
      puts the proper value into the global variable <tt>wiem</tt>).
</p>

<p>
      <b>Note:</b> Don't assume that a program  inspecting the run of experiments actually
      fixes the toughness of eggs before starting the experiment. It can adjust it during
      the experiment, so that it suits to all previously given answers and makes
      your program ask maximum number of questions.
      Thus, you should try to minimize the number of questions, which your program
      would have to
      ask in the worst case.
</p>

<h2>Communication</h2>
<p>
      The communication between your module and the program inspecting the run
      of experiments is done through global variables.

      The number of floors of the skyscraper will be written in the global variable
      <tt>wysokosc</tt> of type <tt>Longint</tt> (in case of C/C++ language the 
      type is  <tt>long int</tt>).
      It will be a positive integer not greater than 100000000.

      The maximal number of eggs that can be broken during the experiment
      will be written in the global variable <tt>jajka</tt> of type <tt>Integer</tt> 
      (in case of C/C++ language the type is  <tt>int</tt>).
      It will be a positive integer not greater than 1000.

      Asking a question if an egg "survives" a fall from the <i>k</i>-th floor,
      is done in the procedure <tt>daj_pytanie</tt> by putting the number
      <i>k</i> into the 
      global variable <tt>pietro</tt> of type <tt>Longint</tt> 
      (in case of C/C++ language the type is  <tt>long int</tt>).

      The answer to the question is put into the global variable <tt>odpowiedz</tt> 
      of type <tt>Boolean</tt> (in case of C/C++ language the type is <tt>int</tt>).
      The confirmation  to the question (i.e. the egg "survives") corresponds
      to the value <tt>TAK</tt>, and a negative answer (i.e. the egg breaks) corresponds to the value
      <tt>NIE</tt>, where <tt>TAK</tt> and <tt>NIE</tt> are constants valued respectively 
      to <tt>true</tt> and <tt>false</tt> (in case of C/C++ language these are macros valued
      respectively to <tt>1</tt> and <tt>0</tt>).

      When your program determines the toughness of the egg it should write in the procedure
      <tt>analizuj_odpowiedz</tt> a value <tt>TAK</tt> into the global variable <tt>wiem</tt> of type 
      <tt>Boolean</tt> (in case of C/C++ language the type is <tt>int</tt>) 
       and the toughness of  the egg found by your program should be written into the global 
      variable <tt>x</tt> of
       type <tt>Longint</tt> (in case of C/C++ language the type is <tt>long int</tt>).
</p>

<h2>Directories and files</h2>
<p>
      People programming in Pascal should prepare their solution in the directory <tt>JAJPAS</tt>, 
      and the ones programming in C/C++ in the directory <tt>JAJC</tt>.

      In the directory <tt>JAJPAS</tt> (or <tt>JAJC</tt>) you'll find the following files:
</p>

      <ul>
        <li><tt>JAJmod.pas</tt> (or <tt>JAJmod.h</tt> and
	<tt>JAJmod.c</tt>)
              -
               a module containing definitions of constants <tt>TAK</tt> and <tt>NIE</tt> and
               declarations of global variables,
        <li><tt>JAJ.pas</tt> - a frame of a module determinig toughness of eggs; you should 
               supply this file with definitions of functions <tt>nowy_eksperyment</tt>, 
               <tt>daj_pytanie</tt> and <tt>analizuj_odpowiedz</tt>
              (for C/C++ programmers headers of these functions are in the file <tt>JAJ.h</tt>,
              you have to write the file <tt>JAJ.C</tt> or <tt>JAJ.cpp</tt> with definitions
              of these functions),
        <li><tt>test.pas</tt> (or <tt>test.c</tt>) - a sample program inspecting the run
              of experiments and using your module.
      </ul>
</p>

<h2>Output</h2>
<p>
      The result of your work should be recorded on a floppy disk as the only file:
      <tt>JAJ.pas</tt>, <tt>JAJ.C</tt> or <tt>JAJ.cpp</tt>.
</p>

</body>

</html>
